<template>
    <div class="page absolute w100 t0">
        <div class="group">
            <group>
                <popup-radio title="店铺" @on-hide="popupHide" :options="storeInfos" v-model="fromfilter.storeNo" placeholder="请选择店铺"></popup-radio>
                <x-input title="手机号码" placeholder-align="right" placeholder="请输入手机号" mask="999 9999 9999" v-model="fromfilter.phone" :max="13" is-type="china-mobile"></x-input>
                <x-input title="姓名" :max="20" placeholder-align="right" placeholder="请输入姓名" v-model="fromfilter.name"></x-input>
            </group>
        </div>
        <div class="buttonbox apply_byn" style="z-index:0" @click="submit" >
            <span>店员申请</span>
        </div>
    </div>
</template>
<script>
import { Group, PopupRadio,GroupTitle,XInput  } from 'vux'
import { Toast } from "mint-ui";
import mixins from 'mixins';
import {queryStoreList,applyStoreUser} from "src/methods/request.js";
export default {
    name:'autumn',
    components: {
        Group,
        PopupRadio,
        GroupTitle,XInput
    },
    mixins:[mixins],
    beforeRouteEnter(to,from,next){
        if(sessionStorage.getItem("isHkb")){
            next(vm=>{
                vm.isLogin = true;
            });
        }else{
            //如果没有登陆就先进入登陆页，然后跳转回来
            next(vm=>{
                vm.$router.push({ path:'/login',query:{ pageUrl: 'clerkApply' }});
            })
        }
    },
    data(){
        return {
            isLogin:false,
            showPopup:false,
            storeInfos:[],
            fromfilter:{
                storeNo:"",
                phone:"",
                name:""
            }
        }
    },
    created(){
        // console.log(this.$store.state.b.isRegisterPhone)
        this.loadData();
    },
    methods:{
        confirmCB(){
            this.showPopup = false;
            this.$store.commit("changeRegState",true);
        },
        //获取订单
        async loadData(val){
            this.$vux.loading.show({text: 'Loading'})
            //获取列表
            //保存查询数据类型
            queryStoreList({}).then(res => {
                    this.$vux.loading.hide()
                    if(res.rspCode == '0000'){
                        this.storeInfos = [];
                        let arr = res.data.storeInfos;
                        arr.map((item, index, array)=>{
                            item.key = item.storeNo
                            item.value = item.storeName
                            this.storeInfos.push(item)
                        });
                    }
                }).catch(error => {
                    console.log(error);
                    this.$vux.loading.hide();
                } );
        },
        popupHide(){
            // console.log(this.fromfilter.storeNo)
        },
        submit(){
            this.$vux.loading.show({
                text: "Loading"
            });
            this.fromfilter.phone = this.fromfilter.phone.replace(/\s*/g,"");
            applyStoreUser({ storeNo: this.fromfilter.storeNo, phone:this.fromfilter.phone,name:this.fromfilter.name})
                .then(
                    // findShareCouponInfo({"shareCouponNo":this.shareCouponNo}).then(
                    response => {
                        if (response.rspCode == "0000") {
                            Toast({ message:'申请成功！',duration:3000});
                            this.$router.push({ path:"/"})
                        }
                        this.$vux.loading.hide();
                    }
                )
                .catch(error => console.log(error));
            setTimeout(() => {
                this.$vux.loading.hide();
            }, 2000);
        }
    }
}
</script>
<style lang="less">
.page{
    background:#f6f6f6;
    min-height:100%;
}
.group{ 
    margin-top: -0.8em;
}
.group .weui-cell .vux-cell-bd p{
    text-align: left;
}
.weui-cell{
    border-bottom: 1px solid #D9D9D9;
}
.weui-label{
    text-align: left;
}
.weui-input{
    text-align: right;
}
.apply_byn{
    font-size: 1.4rem;
    background: #ff3932;
    border: 1px solid #dddddd;
}
</style>
